<?php 
session_start();
if (isset($_POST['u']) && isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
    $u=$_POST['u'];
    $jianyi=trim(addslashes($_POST['jianyi']));
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	$sql="select id from vote where openid='".$openid."'  limit 0, 1";
	$query=$mysqli->query($sql);
    if($query->num_rows>0){
        $mysqli->query("update `vote` set jianyi='".$jianyi."',`msg`='".$u."',`createtime`='".date("Y-m-d H:i:s")."' where openid='".$openid."' ");
    }else{
        $mysqli->query("INSERT INTO `vote` (`openid`,`msg`,`jianyi`,`createtime`) VALUES ('".$openid."','".$u."','".$jianyi."','".date("Y-m-d H:i:s")."') ");
    }
 
    $getU=json_decode($u,true);
    $mysqli->query("delete from `piao` where openid='".$openid."' ");
    foreach ($getU as $id){
        $mysqli->query("INSERT INTO `piao` (`openid`,`uid`,`createtime`) VALUES ('".$openid."','".$id."','".date("Y-m-d H:i:s")."') ");
    }
    echo json_encode(array('s'=>'ok'));
    $mysqli->close();

}else{
    $msg=json_encode(array('s'=>'n'));
}
?>